package com.ysd.lis.service.bac.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.Result;
import com.ysd.lis.entity.bac.BacCultrueInfo;
import com.ysd.lis.mapper.bac.BacCultrueInfoMapper;
import com.ysd.lis.service.bac.BacCultrueInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wanghuaixing
 * @since 2024-04-16
 */
@Service
public class BacCultrueInfoServiceImpl extends ServiceImpl<BacCultrueInfoMapper, BacCultrueInfo> implements BacCultrueInfoService {

    @Autowired
    BacCultrueInfoMapper bacCultrueInfoMapper;

    @Override
    public Result batchAddBacCultrueInfo(List<BacCultrueInfo> bacCultrueInfoList) {
        boolean b = this.saveBatch(bacCultrueInfoList);
        if (b) {
            return Result.succ(1, "添加成功", null);
        } else {
            return Result.fail(400, "添加失败", "");
        }
    }

    @Override
    public Result findBacCultureList(BacCultrueInfo bacCultrueInfo) {
        LambdaQueryWrapper<BacCultrueInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BacCultrueInfo::getDelFlag, 0);
        queryWrapper.eq(BacCultrueInfo::getRptGroup, bacCultrueInfo.getRptGroup());
        Timestamp timestamp = new Timestamp(bacCultrueInfo.getSampleda().getTime());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String formattedDate = sdf.format(timestamp);
        Timestamp startTime = Timestamp.valueOf(formattedDate + " 00:00:00");
        Timestamp endTime = Timestamp.valueOf(formattedDate + " 23:59:59");
        queryWrapper.ge(BacCultrueInfo::getSampleda, startTime);
        queryWrapper.le(BacCultrueInfo::getSampleda, endTime);
        queryWrapper.eq(BacCultrueInfo::getSampleNo, bacCultrueInfo.getSampleNo());


        List<BacCultrueInfo> bacCultrueInfoList = bacCultrueInfoMapper.selectList(queryWrapper);
        return Result.succ(1, "查询成功", bacCultrueInfoList);
    }
}
